<template>

	<view class="class_mulu">
		<mumu-previewOffce :fileUrl='fileUrl' v-model='showPreview'></mumu-previewOffce>
		<view class="tree_mulu">
			<!-- 一级 -->
			<view v-for="(item,ind) in mulunum">
				<view class="mulu_frist" @click="fristZhankai(ind)">
					<text>第{{ind+1}}章&nbsp&nbsp&nbsp{{item.title}}</text>
					<image v-if='item.open==false' class="fristjiantou" :src="fatherToInfo.defaultIcon" mode="">
					</image>
					<image v-if='item.open' class="fristjiantou" :src="fatherToInfo.currentIcon" mode=""></image>
				</view>
				<!-- 二级 -->
				<view v-if='item.open'>
					<view class="mulu_second" v-for="(item1,ind2) in mulunum[ind].courseChapterList"
						style="margin: 0 20px;">
						<view class="mulu_second_view" @click="two(ind,item1,ind2)">
							<text>第{{ind2+1}}节&nbsp{{item1.title}}</text>
							<image v-if="item1.secondOpen==false" class="fristjiantou" :src="fatherToInfo.defaultIcon"
								mode=""></image>
							<image v-if="item1.secondOpen==true" class="fristjiantou" :src="fatherToInfo.currentIcon"
								mode=""></image>
						</view>
						<!-- 三级 -->
						<view v-if="item1.secondOpen== true" class="mulu_third" style="height: auto;"
							v-for="(index3,ind3) in item1.courseVideosList" @click="threelist(index3)">
							<image v-if="index3.thirdOpen==true" class="playIngImg" :src="fatherToInfo.thirdImg"
								mode="">
							</image>
							<view class="third_title" v-if="index3.thirdOpen==false">
								{{index3.title}}
							</view>
							<view class="third_title" v-if="index3.thirdOpen==true"
								:style="[{fontSize:fatherToInfo.thirdfontsize+'rpx',color:fatherToInfo.choosedcolor}]">
								{{index3.vTitle}}
							</view>
							<text class="third_time" v-if="index3.thirdOpen==false"
								:style="[{fontSize:fatherToInfo.thirdrightfontsize+'rpx',color:fatherToInfo.thirdrightcolor}]">{{index3.duration}}
							</text>
							<text class="third_time" v-if="index3.thirdOpen==true"
								:style="[{fontSize:fatherToInfo.thirdrightfontsize+'rpx',color:fatherToInfo.thirdrightchoosed}]">{{index3.duration}}
							</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import MumuPreviewOffce from '@/uni_modules/mumu-previewOffce/components/mumu-previewOffce/mumu-previewOffce.vue'
	export default {
		components: { //声明组件
			MumuPreviewOffce
		},
		data() {
			return {
				fileUrl: '', // office链接
				showPreview: false, //控制是否打开
			}
		},
		onLoad() {

		},
		methods: {
			// 下拉
			fristZhankai(ind) {
				if (this.mulunum[ind].courseChapterList == '') {
					uni.showToast({
						title: '当前章节无资源'
					})
					// return '' // 如果无资源直接return 下面代码不执行
				}
				if (this.fatherToInfo.shoufenq) {
					if (this.mulunum[ind].open == false) {
						this.mulunum[ind].open = true
						console.log(this.mulunum[ind].open);
					} else {
						this.mulunum[ind].open = false
						this.fatherToInfo.shoufenq = false
					}
					// this.mulunum.forEach((index, xb) => {
					// 	if (ind == xb) {
					// 		this.mulunum[ind].open = true
					// 		console.log(2);
					// 		console.log(this.mulunum);
					// 	} else {
					// 		this.mulunum[ind].open = false
					// 		// this.$set(index, 'open', false)
					// 		this.fatherToInfo.shoufenq = false
					// 	}
					// })
				} else {
					if (this.mulunum[ind].open == true) {
						this.$set(this.mulunum[ind], 'open', false)
					} else {
						this.$set(this.mulunum[ind], 'open', true)
					}
				}
				this.$forceUpdate(this.mulunum) // 重新渲染页面  

			},
			// 二级下拉
			two(ind, item1, ind2) {
				console.log(this.mulunum[ind].open);
				if (this.mulunum[ind].courseChapterList[ind2].courseVideosList == '') {
					uni.showToast({
						title: '当前章节无资源'
					})
					return ''
				}
				if (this.mulunum[ind].courseChapterList[ind2].secondOpen === false) {
					console.log(123456);
					this.mulunum[ind].courseChapterList[ind2].secondOpen = true
				} else {
					this.mulunum[ind].courseChapterList[ind2].secondOpen = false

				}
				this.$forceUpdate(this.mulunum) // 重新渲染页面  
			},
			// 判断后缀名
			threelist(resource) {
				console.log(resource);
				// console.log(resource.fileUrl.lastIndexOf('.mp4'))
				if (resource.fileUrl !== '' && resource.fileUrl !== null) {
					let endUrl = resource.fileUrl.substring(resource.fileUrl.lastIndexOf('.') + 1)
					console.log(endUrl)
					// 'pptx', 'ppt', 'docx', 'doc', 'xlsx', 'xls', 'pdf'
					// const arr = ['pptx', 'ppt', 'docx', 'doc', 'xlsx', 'xls', 'pdf']
					if (endUrl == 'pptx' ||
						endUrl == 'ppt' ||
						endUrl == 'docx' ||
						endUrl == 'doc' ||
						endUrl == 'xlsx' ||
						endUrl == 'xls' ||
						endUrl == 'pdf'
					) {
						this.fileUrl = "https://tveti.lcvc.edu.cn/" + resource.fileUrl
						this.showPreview = true
						console.log(this.fileUrl);
					} else if (endUrl == 'mp4') {
						// console.log("这是对象: "+JSON.stringify(resource));
						// uni.setStorageSync('resource',resource) // 放进缓存
						uni.navigateTo({
							url: "../../pages/course/courseSpace/courseSpace?fileUrl=" + resource.fileUrl +
								'&sectionResourceId=' + resource.sectionResourceId
						})
						console.log(resource.fileUrl)
					} else if (endUrl == 'png' || endUrl == 'jgp') { //图片
						console.log("图片");
					}
				} else {
					console.log("无资源");
					uni.showToast({
						title: "无资源"
					})
				}
			},

		},
		props: ["mulunum", "fatherToInfo"], // 接收数据
	}
</script>

<style lang="scss">
	.class_mulu {
		width: 100%;

		.jieshao_class {
			width: 100%;
			height: 84rpx;
			line-height: 84rpx;
			padding: 0 20rpx;
			box-sizing: border-box;

			.jieshao_title {
				color: #333333;
			}

			.jieshao_time {
				font-size: 24rpx;
				color: #333333;
				float: right;
			}

			.choosedcolor {
				color: #3c87ca;
			}
		}

		.tree_mulu {
			width: 100%;
			margin: 20rpx 0;

			.mulu_frist {
				margin: 20rpx;
				padding: 0px 3%;
				box-sizing: border-box;
				position: relative;
				height: 90rpx;
				line-height: 90rpx;
				border-radius: 30rpx;
				box-shadow: 0 0 6rpx #424d5a;
				font-size: 15px;

				text {
					color: #2ebbfe;
					margin-left: 10px;
				}

				.fristImg {
					width: 24rpx;
					height: 24rpx;
					// position: absolute;
					top: 0;
					bottom: 0;
					left: 36rpx;
					margin-left: 10rpx;
				}

				.fristjiantou {
					width: 44rpx;
					height: 44rpx;
					position: absolute;
					top: 0;
					bottom: 0;
					right: 4%;
					margin: auto;
				}
			}

			.mulu_second {
				.mulu_second_view {
					font-size: 15px;
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					border-bottom: 1px #f1f1f1 solid;
					box-sizing: border-box;
					position: relative;
				}

				.fristImg {
					width: 24rpx;
					height: 24rpx;
					position: absolute;
					top: 0;
					bottom: 0;
					left: 50rpx;
					margin: auto;
				}

				text {
					color: #333333;
					margin-left: 30rpx;
				}

				.fristjiantou {
					width: 44rpx;
					height: 44rpx;
					position: absolute;
					top: 0;
					bottom: 0;
					right: 2%;
					margin: auto;
				}
			}

			.mulu_third {
				width: 100%;
				font-size: 15px;
				// padding: 0 40rpx;
				// padding: 0 20rpx 0 84rpx;
				margin: 0 30px;
				box-sizing: border-box;
				position: relative;
				height: 80rpx;

				.playIngImg {
					width: 20rpx;
					height: 20rpx;
					// margin: auto;
					margin-right: 20rpx;
				}

				.third_title {
					color: #666;
					width: 60%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					display: inline-flex;
					margin-left: 0;
					line-height: 80rpx;
				}

				.third_time {
					color: #666;
					line-height: 70rpx;
					float: right;
				}

				.choosedvideo {
					color: #3c87ca;
				}
			}
		}
	}
</style>
